package com.jews.common.constants;

import java.util.Optional;

/**
 * @author JewsChen
 * @title: ValidStatus
 * @date 2022/8/17 22:11
 */
public enum ValidStatus implements BaseEnum<ValidStatus> {

    /**
     * 有效/启用
     */
    VALID(1, "启用"),

    /**
     * 无效/停用
     */
    INVALID(2, "停用"),

    /**
     * 删除
     */
    DELETE(3, "删除");

    ValidStatus(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Integer code;
    private String msg;

    /**
     * 获取code码存入数据库
     *
     * @return 获取编码
     */
    @Override
    public Integer getCode() {
        return this.code;
    }

    /**
     * 获取编码名称，便于维护
     *
     * @return 获取编码名称
     */
    @Override
    public String getName() {
        return this.msg;
    }

    public static Optional<ValidStatus> of(Integer code) {
        return Optional.ofNullable(BaseEnum.parseByCode(ValidStatus.class, code));
    }

}
